#include <vector>
#include <string>
#include <iostream>
using namespace std;

//给定行和列的和 求可行的矩阵
class Solution {
public:
    vector<vector<int>> restoreMatrix(vector<int>& rowSum, vector<int>& colSum) 
    {
        vector<vector<int>>res(rowSum.size(),vector<int>(colSum.size(),0));
        for(int i=0;i<rowSum.size();i++)
        {
            for(int j=0;j<colSum.size();j++)
            {
                res[i][j]=min(rowSum[i],colSum[j]);
                rowSum[i]-=res[i][j];
                colSum[j]-=res[i][j];
            }
        }
        return res;
    }
};

//合法括号序列判断
class Parenthesis {
public:
    bool chkParenthesis(string A, int n) 
    {
        if(n%2 !=0) return false;
        stack<char> st;
        for(auto& ch:A)
        {
            if(ch=='(')
            {
                st.push(ch);    
            }
            else if (!st.empty() &&st.top()=='(' && ch==')'  )
            {
                st.pop();
            }
            else
            {
                return false;
            }
        }
        return st.empty();
    }
};

//斐波那契数列最小差值
#include <iostream>
#include <vector>
using namespace std;
 
int main() 
{
    int n;
    cin>>n;
    int f;
    int f1=0,f2=1;
    int left=0,right=0;
    int res=0;
    while(1)
    {
        f=f1+f2;
        if(n==f || n==f1 || n==f2)
        {
            break;
        }
        if(f>n)
        {
            left=f2;
            right=f;
            res=min(n-left,right-n);
            break;
        }
        f1=f2;
        f2=f;
        
    }
    cout<<res<<endl;
    return 0;
}